import uniqueId from '@form-create/utils/lib/unique'
import { localeProps } from '../utils'

export const useUploadImgRule = () => {
  const label = '单图上传'
  const name = 'UploadImg'
  return {
    icon: 'icon-upload', // 复用已有icon
    label,
    name,
    rule() {
      // 定义组件的渲染规则，对应该组件在form create中的rule，组件拖拽出来的初始规则值，后续通过下面配置的props构成的右侧配置表单项目，进行该rule的props的变更
      return {
        type: name,
        field: uniqueId(),
        title: label,
        info: '',
        $required: false,
        props: {}
      }
    },
    props(_, { t }) {
      // 配置UploadImg的props属性值
      // 构建该组件的右侧配置项目，使用form create的rule定制动态表单
      // localeProps将rule的title转为国际化，若有必要
      return localeProps(t, name + '.props', [
        // makeRequiredRule(), // 是否必填
        {
          type: 'select',
          field: 'fileType',
          title: '图片类型限制',
          value: ['image/jpeg', 'image/png'],
          options: [
            { label: 'image/png', value: 'image/png' },
            { label: 'image/jpeg', value: 'image/jpeg' },
            { label: 'image/bmp', value: 'image/bmp' },
            { label: 'image/gif', value: 'image/gif' },
            { label: 'image/apng', value: 'image/apng' },
            { label: 'image/pjpeg', value: 'image/pjpeg' },
            { label: 'image/svg+xml', value: 'image/svg+xml' },
            { label: 'image/tiff', value: 'image/tiff' },
            { label: 'image/webp', value: 'image/webp' },
            { label: 'image/x-icon', value: 'image/x-icon' }
          ],
          props: {
            multiple: true
          }
        },
        {
          type: 'inputNumber',
          field: 'fileSize',
          title: '大小限制(MB)',
          value: 5,
          props: { min: 0 }
        },
        {
          type: 'switch',
          field: 'drag',
          title: '是否支持拖拽上传',
          value: false
        },
        {
          type: 'input',
          field: 'width',
          title: '组件宽度',
          value: '150px'
        },
        {
          type: 'input',
          field: 'height',
          title: '组件高度',
          value: '150px'
        },
        {
          type: 'input',
          field: 'borderradius',
          title: '组件边框圆角',
          value: '8px'
        },
        {
          type: 'switch',
          field: 'showDelete',
          title: '是否显示删除按钮',
          value: true
        },
        {
          type: 'switch',
          field: 'showBtnText',
          title: '是否显示按钮文字',
          value: true
        },
        {
          type: 'switch',
          field: 'disabled',
          title: '是否禁用',
          value: true
        }
      ])
    }
  }
}
